﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DAO;
using DVO;

/// <summary>
/// Summary description for BLL_Document
/// </summary>
public class BLL_Document : DocumentDataContext
{
	public BLL_Document()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public int Update_Document(int docid, int status)
    {
        int IdReturn = 0;
        try
        {
            IdReturn = ins_Document_Update(docid, status);
        }
        catch (Exception ex)
        {
            Common.WriteLog(ex.Message, ex.StackTrace);
        }
        return IdReturn;
    }

    public int Document_Insert(Document ObjInfo)
    {
        int IdReturn = 0;
        try
        {
            IdReturn = ins_Document_InsertUpdate(ObjInfo.DocumentName, ObjInfo.LinkDocument, ObjInfo.WorkId, ObjInfo.Id,ObjInfo.Notes);
        }
        catch (Exception ex)
        {
            Common.WriteLog(ex.Message, ex.StackTrace);
        }
        return IdReturn;
    }

    public ins_Document_SelectByIdResult Document_SelectById(int Id)
    {
        ins_Document_SelectByIdResult objList = new ins_Document_SelectByIdResult();
        try
        {
            objList = ins_Document_SelectById(Id).SingleOrDefault();
        }
        catch (Exception ex)
        {
            Common.WriteLog(ex.Message, ex.StackTrace);
        }
        return objList;
    }

    public List<ins_Document_SelectByWorkIdResult> Document_SelectByWorkId(int workId)
    {
        List<ins_Document_SelectByWorkIdResult> ObjList = new List<ins_Document_SelectByWorkIdResult>();
        try
        {
            ObjList = ins_Document_SelectByWorkId(workId).ToList();
        }
        catch (Exception ex)
        {
            Common.WriteLog(ex.Message, ex.StackTrace);
        }
        return ObjList;
    }

    public List<ins_Document_SearchResult> Document_SearchCheck(string Id, string DocumentName,string Author)
    {
        List<ins_Document_SearchResult> ObjList = new List<ins_Document_SearchResult>();
        int documentid = 0;
        try
        {
            if (string.IsNullOrEmpty(Id))
                documentid = 0;
            else
                documentid = Convert.ToInt32(Id);
                ObjList = ins_Document_Search(documentid,DocumentName,Author).ToList();
        }
        catch (Exception ex)
        {
            Common.WriteLog(ex.Message, ex.StackTrace);
        }
        return ObjList;
    }

    public List<ins_Document_SearchCheckResult> Document_SearchAgree(string Id, string documentName, string author, string username)
    {
        List<ins_Document_SearchCheckResult> Objlist = new List<ins_Document_SearchCheckResult>();
        int documentid = 0;
        
            try
            {
                if (string.IsNullOrEmpty(Id))
                    documentid = 0;
                else
                    documentid = Convert.ToInt32(Id);
                Objlist = ins_Document_SearchCheck(documentid, documentName, author, username).ToList();
            }
            catch (Exception ex)
            {
                Common.WriteLog(ex.Message, ex.StackTrace);
            }
            return Objlist;
       
    }
}